export default {
  install: function(Vue) {
    Vue.prototype.isJSON = function(str) {
      if (typeof str === "string") {
        try {
          var obj = JSON.parse(str);
          if (typeof obj === "object" && obj) {
            return true;
          } else {
            return false;
          }
        } catch (e) {
          return false;
        }
      }
    };
    Vue.prototype.timestampToTime = function(time, cFormat) {
      if (arguments.length === 0) {
        return null;
      }
      const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
      let date;
      if (typeof time === "object") {
        date = time;
      } else {
        if (("" + time).length === 10) time = parseInt(time);
        date = new Date(time);
      }
      const formatObj = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds(),
        a: date.getDay()
      };
      const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
        let value = formatObj[key];
        if (key === "a") {
          return ["一", "二", "三", "四", "五", "六", "日"][value - 1];
        }
        if (result.length > 0 && value < 10) {
          value = "0" + value;
        }
        return value || 0;
      });
      return time_str;
    };
    Vue.prototype.cutDate = function(date) {
      const dateArr = date.split("-");
      return dateArr[1] + "-" + dateArr[2];
    };
    Vue.prototype.merchantStatusEs = function(status) {
      switch (parseInt(status)) {
        case 0:
          return "经营中";
        case 1:
          return "注册中";
        case 2:
          return "审核不通过";
        case 3:
          return "停业";
        case 4:
          return "审核中";
        default:
          return status;
      }
    };
    Vue.prototype.shelfEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "上架";
        case 2:
          return "下架";
        default:
          return status;
      }
    };
    Vue.prototype.typeEstimation = function(type) {
      switch (parseInt(type)) {
        case 1:
          return "关机";
        case 2:
          return "正常";
        case 3:
          return "故障";
        default:
          return type;
      }
    };
    Vue.prototype.typeEs = function(type) {
      switch (parseInt(type)) {
        case 1:
          return "开机";
        case 2:
          return "关机";
        case 3:
          return "网络异常";
        default:
          return type;
      }
    };
    Vue.prototype.faultTypeEs = function(type) {
      switch (parseInt(type)) {
        case 1:
          return "硬件故障";
        case 2:
          return "系统故障";
        case 3:
          return "网络故障";
        case 4:
          return "其他故障";
        default:
          return type;
      }
    };
    Vue.prototype.regionTypeEs = function(type) {
      switch (parseInt(type)) {
        case 0:
          return "国家";
        case 1:
          return "省份";
        case 2:
          return "城市";
        case 3:
          return "区/县";
        default:
          return type;
      }
    };
    Vue.prototype.statusColor = function(status) {
      switch (parseInt(status)) {
        case 0:
          return "colorGreen";
        case 1:
          return "colorGreen";
        case 2:
          return "colorRed";
        case 3:
          return "colorRed";
        default:
          return "";
      }
    };
    Vue.prototype.brandTypeEstimation = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "商品";
        case 2:
          return "设备";
        default:
          return status;
      }
    };
    Vue.prototype.cargoLaneEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "正常";
        case 2:
          return "缺货";
        case 3:
          return "故障";
        case 4:
          return "停用";
        case 5:
          return "隐藏";
        default:
          return status;
      }
    };
    Vue.prototype.orderStatusEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待审核";
        case 2:
          return "待采购";
        case 3:
          return "待发货";
        case 4:
          return "待收货";
        case 5:
          return "已完成";
        case 6:
          return "审核驳回";
        default:
          return status;
      }
    };
    Vue.prototype.purchaseStatusEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待配餐";
        case 2:
          return "待取货";
        case 3:
          return "待送餐";
        case 4:
          return "已完成";
        default:
          return status;
      }
    };
    Vue.prototype.orderStatus = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待审核";
        case 2:
          return "待发货";
        case 3:
          return "待收货";
        case 4:
          return "已完成";
        case 5:
          return "审核驳回";
        default:
          return status;
      }
    };
    Vue.prototype.pickUpEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待备货";
        case 2:
          return "待提货";
        case 3:
          return "已完成";
        case 4:
          return "未通过";
        default:
          return status;
      }
    };
    Vue.prototype.warehouseEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待入库";
        case 2:
          return "已完成";
        default:
          return status;
      }
    };
    Vue.prototype.effectiveEs = function(type) {
      switch (parseInt(type)) {
        case 1:
          return "立即生效";
        case 2:
          return "区间调价";
        case 3:
          return "设定时间";
        default:
          return type;
      }
    };
    Vue.prototype.applicationEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待审核";
        case 2:
          return "已通过";
        case 3:
          return "未通过";
        default:
          return status;
      }
    };
    Vue.prototype.paymentMethodEs = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "微信";
        case 2:
          return "支付宝";
        case 3:
          return "云闪付";
        default:
          return status;
      }
    };
    Vue.prototype.warehouseEs = function(type) {
      switch (parseInt(type)) {
        case 1:
          return "出库";
        case 2:
          return "入库";
        default:
          return type;
      }
    };
    Vue.prototype.warehouse = function(type) {
      switch (parseInt(type)) {
        case 1:
          return "调拨";
        case 2:
          return "提货";
        case 3:
          return "采购";
        default:
          return type;
      }
    };
    Vue.prototype.serviceStatus = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待维修";
        case 2:
          return "已完成";
        default:
          return status;
      }
    };
    Vue.prototype.orderStatus = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "待取";
        case 2:
          return "已取";
        case 3:
          return "已过期";
        default:
          return status;
      }
    };
    Vue.prototype.orderType = function(status, type) {
      if (type === 3) {
        return "已失效";
      } else if (type === 1) {
        return "待支付";
      } else if (type === 2 && status === 1) {
        return "待取餐";
      } else if (type === 2 && status === 3) {
        return "已逾期";
      } else if (type === 2 && status === 2) {
        return "已完成";
      }
    };
    Vue.prototype.mealsStatus = function(status) {
      switch (parseInt(status)) {
        case 1:
          return "暂存";
        case 2:
          return "待确认";
        case 3:
          return "退回";
        case 4:
          return "待发布";
        case 5:
          return "已发布";
        default:
          return status;
      }
    };
    Vue.prototype.assessStatus = function(status) {
      switch (parseInt(status)) {
        case 0:
          return "待回复";
        case 1:
          return "已回复";
        default:
          return status;
      }
    };
    Vue.prototype.bindStatus = function(status) {
      switch (parseInt(status)) {
        case 0:
          return "未绑定";
        case 1:
          return "已绑定";
        default:
          return status;
      }
    };
    Vue.prototype.dateEs = function(date, data) {
      const myDate = new Date();
      const tYear = myDate.getFullYear();
      const tMonth = myDate.getMonth();
      switch (date) {
        case 1:
          switch (data) {
            case 0:
              return tMonth + 1 + "月";
            case 1:
              return tMonth + "月";
            case 2:
              return tMonth - 1 > 0 ? tMonth - 1 + "月" : tMonth + 11 + "月";
            case 3:
              return tMonth - 2 > 0 ? tMonth - 2 + "月" : tMonth + 10 + "月";
            case 4:
              return tMonth - 3 > 0 ? tMonth - 3 + "月" : tMonth + 9 + "月";
            case 5:
              return tMonth - 4 > 0 ? tMonth - 4 + "月" : tMonth + 8 + "月";
            default:
              break;
          }
          break;
        case 2:
          switch (data) {
            case 0:
              return "本周";
            case 1:
              return "上周";
            case 2:
              return "前两周";
            case 3:
              return "前三周";
            case 4:
              return "前四周";
            case 5:
              return "前五周";
            default:
              break;
          }
          break;
        case 3:
          if (tMonth >= 0 && tMonth <= 2) {
            switch (data) {
              case 0:
                return tYear + "年第一季度";
              case 1:
                return tYear - 1 + "年第四季度";
              case 2:
                return tYear - 1 + "年第三季度";
              case 3:
                return tYear - 1 + "年第二季度";
              case 4:
                return tYear - 1 + "年第-季度";
              case 5:
                return tYear - 2 + "年第四季度";
              default:
                break;
            }
            break;
          } else if (tMonth >= 3 && tMonth <= 5) {
            switch (data) {
              case 0:
                return tYear + "年第二季度";
              case 1:
                return tYear + "年第一季度";
              case 2:
                return tYear - 1 + "年第四季度";
              case 3:
                return tYear - 1 + "年第三季度";
              case 4:
                return tYear - 1 + "年第二季度";
              case 5:
                return tYear - 1 + "年第一季度";
              default:
                break;
            }
            break;
          } else if (tMonth >= 6 && tMonth <= 8) {
            switch (data) {
              case 0:
                return tYear + "年第三季度";
              case 1:
                return tYear + "年第二季度";
              case 2:
                return tYear + "年第一季度";
              case 3:
                return tYear - 1 + "年第四季度";
              case 4:
                return tYear - 1 + "年第三季度";
              case 5:
                return tYear - 1 + "年第二季度";
              default:
                break;
            }
            break;
          } else if (tMonth >= 9 && tMonth <= 11) {
            switch (data) {
              case 0:
                return tYear + "年第四季度";
              case 1:
                return tYear + "年第三季度";
              case 2:
                return tYear + "年第二季度";
              case 3:
                return tYear + "年第一季度";
              case 4:
                return tYear - 1 + "年第四季度";
              case 5:
                return tYear - 1 + "年第三季度";
              default:
                break;
            }
            break;
          }
          break;
        case 4:
          switch (data) {
            case 0:
              return tYear + "年";
            case 1:
              return tYear - 1 + "年";
            case 2:
              return tYear - 2 + "年";
            case 3:
              return tYear - 3 + "年";
            case 4:
              return tYear - 4 + "年";
            case 5:
              return tYear - 5 + "年";
            default:
              break;
          }
          break;
        default:
          break;
      }
    };
  }
};
